This invention relates generally to computer shared memory systems, and more particularly to representing pointers to objects stored in shared memory.
A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever. The following notice applies to the software and data as described below and in the drawing hereto: Copyright (copyright)1997, Microsoft Corporation, All Rights Reserved.
Multiprocessing computer systems require that more than one process can open a data file at a time. On a shared memory system, the status information, or state, for an open file is usually stored in the shared memory so that a single copy of the state information can be accessed by all the processes that have the file open. The memory area containing the state information is often referred to as a xe2x80x9cheap.xe2x80x9d Each item of state information is stored in a data structure in the heap and thus can be referenced using a pointer which contains the address of the structure within the heap. Therefore, when two processes need to communicate with one another regarding the state of a commonly open file, instead of incurring the overhead associated with passing the entire data structure in a buffer, they merely pass the pointer to the structure in the heap. Using pointers instead of buffers results in major performance gains.
Other types of data structures which can be referenced by more than one process are also stored in a shared memory heap and the pointers to those structures are similarly passed when inter-process communication is necessary. In an object-based computer system, the data structures stored in the heap are objects of various classes which contain information that must be communicated between two or more processes.
Each process in a shared memory system executes within its own virtual address space which is mapped into the physical memory. The address of the heap is defined within the virtual address space for each process. However, the addresses for the heap, and those of the items or objects in the heap, are different for each process. Using a pointer containing an address that is valid in the address space of in one process as the pointer means that the second process will view the address in the pointer as erroneous or will retrieve the wrong information.
One solution is to use relative pointers to reference objects in the file for inter-process communications. A relative pointer contains an address, or offset, that is relative to the start, or base address, of the heap. To access the information, a process adds the offset to the base address it has for the heap.
Using relative pointers presents its own problems. Each process must store its base address for the heap in memory, usually in a global variable so that all threads of the process have access to the base address. However, if a process must address more than one heap (because, for example, it has more than one file open), it must maintain a like number of global variables, and reinitialize the current base address when switching between the heaps. Alternatively, if each heap is associated with only one thread, the responsible thread can store the virtual address of the heap in thread local storage but this solution requires swapping thread contexts when switching between heaps, an expensive operation.
Therefore, there is a need in the art for a way to represent pointers to objects in shared memory heaps that leverages the performance gains achievable through the use of pointers but without the overhead currently associated with relative pointers. Such a pointer representation should also be capable of being transparently implemented in current programming environments.
The above-mentioned shortcomings, disadvantages and problems are addressed by the present invention, which will be understood by reading and studying the following specification.
A smart pointer contains two based addresses which are offsets relative to the start of a shared memory heap. One of the based addresses, a destination-pointer, is the offset of a data structure in the heap pointed to by the smart pointer. The other based address, a this-pointer, is the offset of the smart pointer itself. The smart pointer has a self-referencing property which returns an absolute address of the smart pointer within the address space of a process that has opened the heap in shared memory. The absolute address of the data structure pointed to by the smart pointer is calculated by subtracting the this-pointer from the absolute address of the smart pointer and then adding the destination-pointer. When more than one process has the same heap open in shared memory, the smart pointer is used to marshal a data structure between the processes.
The self-referencing property and the conversion method associated with the smart pointer guarantees that the data structure pointed to by the smart pointer will always be addressed correctly by any process that references the smart pointer. Standard pointer operations can be carried out efficiently by comparing the offset values in the destination-pointers instead of converting to the corresponding absolute addresses. A NULL pointer is also efficiently represented by setting the destination-pointer to zero.
Because the smart pointer of the present invention carries its own offset from the start of the shared memory heap, a process does not need to save the base address of the heap in its address space. Furthermore, the simplicity of the calculations required to resolve the relative address of the destination-pointer into an absolute address within a process""s address space means that the additional processing cost of using smart pointers is minimal. Therefore, the smart pointer provides an efficient solution to the problems of representing pointers in a multiprocessing environment without the performance degradation associated with previous relative address pointers.
The present invention describes systems, clients, servers, methods, and computer-readable media of varying scope. In addition to the aspects and advantages of the present invention described in this summary, further aspects and advantages of the invention will become apparent by reference to the drawings and by reading the detailed description that follows.